<template>
    <el-dialog v-model="dialogVisible" title="请选择用户标签" width="540">
        <el-form v-for="item in userTagByLabelData.data" label-position="top">
            <el-form-item :label="item.name + ':'">
                <div>
                    <el-space wrap>
                        <el-check-tag v-for="temp in item.tags" @click="onChoseTag(temp)"
                            :checked="choseTag.includes(temp._id)" 
                            style="font-weight: normal;cursor: pointer;font-size: 12px; ;" type="primary">
                            {{ temp.name }}
                        </el-check-tag>
                    </el-space>
                </div>
            </el-form-item>
        </el-form>
        <div style="text-align: end;">
            <el-button @click="closeDialog">取消</el-button>
            <el-button type="primary" @click="addTagToAddItem">确认</el-button>
        </div>
    </el-dialog>
</template>

<script setup lang="ts">
import { useFindData } from '@/composables/findData';
import { reactive, ref } from 'vue';
import { onMounted } from 'vue';
let choseTag: Array<any> = reactive([]);
const dialogVisible = ref(false);
const emit = defineEmits(['getCheckedUserTag']);
const { userTagByLabelData, getUserTagByLabelJoint, } = useFindData();
onMounted(() => { getUserTagByLabelJoint(); });
defineExpose({ openUserTagDialog });
const onChoseTag = (data: { _id: string, name: string }) => {
    if (choseTag.includes(data._id)) {
        choseTag = choseTag.filter(item => item != data._id);
    } else {
        choseTag.push(data);
    }
}

// function baColorChange (data:any){
//     if(choseTag.includes(data)){
//         return '#0256FF'
//     }else{
//         return '#909399'
//     }
// }
function openUserTagDialog() {
    dialogVisible.value = true;
}

function addTagToAddItem() {
    emit('getCheckedUserTag', choseTag);
    dialogVisible.value = false;
}
function closeDialog() {
    dialogVisible.value = false;
}

</script>

<style scoped>

</style>